package com.project.personnel.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.personnel.entity.Employeetrain;
import com.project.personnel.service.EmployeetrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author diaominyh
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/employeetrain")
public class EmployeetrainController {
    @Autowired
    private EmployeetrainService employeetrainService;

    //添加
    @PostMapping("/add")
    public boolean add(@RequestBody Employeetrain employeetrain) {
        return employeetrainService.save(employeetrain);
    }

    //查询列表
    /*@RequestMapping("/list")
    public List<Employeetrain> list(Integer id){
        return employeetrainService.list();
    }*/
    //删除
    @GetMapping("/del/{id}")
    public int del(@PathVariable Integer id) {
        return employeetrainService.deleteById(id);
    }
    //分页
    @GetMapping("/getpage")
    public List<Employeetrain> getPage(Integer current,Integer size){
        Page<Employeetrain> employeetrainPage = new Page<>(current,size);
        IPage<Employeetrain> employeetrainIPage = employeetrainService.page(employeetrainPage);
        return employeetrainIPage.getRecords();
    }
    //根据日期查询
    @GetMapping("/datepage")
    public List<Employeetrain> dataPage(Integer current, Integer size, Date date){
        Page<Employeetrain> employeetrainPage = new Page<>(current,size);
        QueryWrapper<Employeetrain> employeetrainQueryWrapper = new QueryWrapper<>();
        employeetrainQueryWrapper.eq("trainDate",date);
        IPage<Employeetrain> employeetrainIPage = employeetrainService.page(employeetrainPage,employeetrainQueryWrapper);
        return employeetrainIPage.getRecords();
    }
    //根据姓名查询
    @GetMapping("/namepage")
    public List<Employeetrain> namePage(Integer current, Integer size, String name){
        Page<Employeetrain> employeetrainPage = new Page<>(current,size);
        QueryWrapper<Employeetrain> employeetrainQueryWrapper = new QueryWrapper<>();
        employeetrainQueryWrapper.eq("empName",name);
        IPage<Employeetrain> employeetrainIPage = employeetrainService.page(employeetrainPage,employeetrainQueryWrapper);
        return employeetrainIPage.getRecords();
    }
    //批量删除
    @DeleteMapping("/dels")
    public boolean dels(@RequestParam("id") List<Integer> list){
        return employeetrainService.removeByIds(list);
    }

}

